<template>
	<view >
		<view class="item" v-for="(res, index) in siteList" :key="res.id">
			<view class="top" @click="backOrder(res.id)">
				<view class="name">{{ res.name }}</view>
				<view class="phone">{{ res.phone }}</view>
				<view class="tag" v-show="res.is_default==1 ? true : 0">
					<text >默认</text>
					<!-- <text v-for="(item, index) in res.tag" :key="index" :class="{red:item.tagText=='默认'}">{{ item.tagText }}</text> -->
				</view>
			</view>
			<view class="bottom">
				<u--text size="10" class="u-line-2" :text="res.province+res.city+res.county+' '+res.address">{{res.province+res.city+res.county+" "+res.address}}</u--text>
				<view style="display: flex;">
					<u-icon  @click="addressChange(res.id)"   name="edit-pen" :size="40" color="#999999"></u-icon>
					<u-icon name="trash" @click="addressDelete(res.id)" :size="40" color="#999999"></u-icon>
				</view>
			</view>
		</view>
		<view class="addSite" @tap="toAddSite">
			<view class="add">
				<u-icon name="plus" color="#ffffff" class="icon" :size="30"></u-icon>新建收货地址
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			siteList: []
		};
	},
	onLoad() {
		this.getData();
	},
	methods: {
		onLoad(){
			this.getData();
		},
		async getData() {
			const addrelist = await uni.$u.api.addressList();
			console.log(addrelist);
			this.siteList = addrelist.data;
		},
		toAddSite(){
			uni.navigateTo({
			    url: '/pages/address/addSite'
			});
		},
		addressChange(id){
			let url = '/pages/address/addSite?id='+id
			uni.navigateTo({
			    url: url
			});
		},
		async addressDelete(id){
			const res = await uni.$u.api.addressDelete(id);
			uni.navigateTo({
			    url: '/pages/address/address'
			});
		},
		backOrder(id){
			const res = getCurrentPages();
			// console.log(res);
			// if(res[res.length-1])
			if(res[res.length-2].route === "pages/center/center"){
				console.log("个人中心页面转来不跳转");
				return false;
			}else{
				console.log("跳转到订单页面");
				let url = res[res.length-2].route+"?id="+id;  //这个川汇区主要是为了方便查找对应的地址
				uni.$u.route({
					type: 'reLaunch',
					url: url
				});
			}
		}
		
	}
};
</script>

<style lang="scss" scoped>
.item {
	padding: 40rpx 20rpx;
	.top {
		display: flex;
		font-weight: bold;
		font-size: 34rpx;
		.phone {
			margin-left: 60rpx;
		}
		.tag {
			display: flex;
			font-weight: normal;
			align-items: center;
			text {
				display: block;
				width: 60rpx;
				height: 34rpx;
				line-height: 34rpx;
				color: #ffffff;
				font-size: 20rpx;
				border-radius: 6rpx;
				text-align: center;
				margin-left: 30rpx;
				background-color:rgb(49, 145, 253);
			}
			.red{
				background-color:red
			}
		}
	}
	.bottom {
		display: flex;
		margin-top: 20rpx;
		font-size: 28rpx;
		justify-content: space-between;
		color: #999999;
	}
}
.addSite {
	display: flex;
	justify-content: space-around;
	width: 600rpx;
	line-height: 100rpx;
	position: absolute;
	bottom: 30rpx;
	left: 80rpx;
	background-color: red;
	border-radius: 60rpx;
	font-size: 30rpx;
	.add{
		display: flex;
		align-items: center;
		color: #ffffff;
		.icon{
			margin-right: 10rpx;
		}
	}
}
</style>
